package com.itheima.tlias08_14.aop.cglib;

import org.springframework.cglib.proxy.Enhancer;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

public class TestCglib {
    public static void main(String[] args) {
//        创建增强器对象
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(Dmr.class);
        enhancer.setCallback(new Interceptor());
        Dmr dmr = (Dmr) enhancer.create();
        dmr.playGame();
        dmr.playGame();


        Class<Student> studentClass = Student.class;
        try {
            Method study = studentClass.getDeclaredMethod("study");
            Object invoke = study.invoke(new Student());
            System.out.println("获取到的返回值"+invoke);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}


class Student {
    public String study() {
        System.out.println("学生正在学习...");
        Integer[] s = new Integer[10];
        for (int i = 0; i < 10; i++) {
            s [i] = i;
        }
        String string = Arrays.toString(s);
        return string;
    }
}
